﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DTO;
using BUS;

namespace nhakhoachauau
{
    public partial class WebForm7 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Q_BUSNhanVien BUSnv = new Q_BUSNhanVien();
            List<NhanVien> ds = BUSnv.DanhSachNhanVien();
            int i = 1;
            if (ds != null)
                i = ds.Count + 1;
            string MaNV = "NV_" + DateTime.Now.Day + DateTime.Now.Month + DateTime.Now.Year + "_" + i;
            txtMaNV.Attributes["value"] = MaNV;
        }

        protected void btnThemNhanVien_Click(object sender, EventArgs e)
        {
            NhanVien nv = new NhanVien();
            nv.ma_nhan_vien = txtMaNV.Attributes["value"];
            nv.ho_ten = txtHoTen.Attributes["value"];
            nv.dia_chi = txtDiaChi.Attributes["value"];
            nv.nam_sinh = DateTime.Parse(txtNgaySinh.Attributes["value"]);
            nv.dien_thoai = txtDienThoai.Attributes["value"];
            nv.id_loainhanvien = int.Parse(ddlChucVu.Value);
            nv.cmnd = txtCMND.Attributes["value"];
            if (cbGioiTinh.Checked == true)
                nv.gioi_tinh = "Nam";
            else nv.gioi_tinh = "Nữ";
            if (checkIsDangNhap.Checked == true)
            {
                nv.dang_nhap_he_thong = true;
                nv.mat_khau = txtMatKhau.Attributes["value"];
            }
            else
                nv.dang_nhap_he_thong = false;
            nv.ngay_vao_lam = DateTime.Now.Date;
            nv.tinh_trang_lam_viec = true;
            nv.tinh_trang_tai_khoan = (int)enumTinhTrangTaiKhoan.DANGHOATDONG;
            Q_BUSNhanVien BUSnv = new Q_BUSNhanVien();
            try
            {
                BUSnv.ThemNhanVien(nv);
                Response.Write("<script>alert('Thêm nhân viên thành công!')</script>");
                Response.Redirect("~/them-nhan-vien.aspx");
            }
            catch (Exception ex)
            {
                
            }
        }
    }
}